﻿using BCCommon;
using BCDto.WeChatComponent.WeChatKeyword;
using BCService.WeChatComponent.WeChatKeywordService;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BCTMSRESTful.Controllers.Management.WeChat
{
    /// <summary>
    /// 微信关键字回复控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class WeChatKeywordController : ManagementBaseController
    {
        private readonly IWeChatKeywordService weChatKeywordService;

        public WeChatKeywordController(IWeChatKeywordService weChatKeywordService)
        {
            this.weChatKeywordService = weChatKeywordService;
        }

        /// <summary>
        /// 添加微信关键字信息。
        /// </summary>
        /// <param name="dto">微信关键字信息</param>
        /// <response code="201">已添加成功的微信关键字信息。</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(WeChatKeywordDto), 200)]
        public IActionResult Post([FromBody]WeChatKeywordRequestDto dto)
        {
            WeChatKeywordDto result = this.weChatKeywordService.Create(dto);
            return this.Created(string.Format("/api/v1/sim/WeChatKeyword/{0}", result.WeChatKeywordId), result);
        }

        /// <summary>
        /// 获取微信关键字信息。
        /// </summary>
        /// <response code="200"></response>
        /// <returns></returns>
        [HttpGet("{we_chat_keyword_id}")]
        [ProducesResponseType(typeof(WeChatKeywordDto), 200)]
        public IActionResult Get([FromRoute(Name = "we_chat_keyword_id")]int weChatKeywordId)
        {
            return this.Ok(this.weChatKeywordService.GetWeChatKeywordById(weChatKeywordId));
        }
        /// <summary>
        /// 获取微信关键字列表（分页）。
        /// </summary>        
        /// <param name="keyword">关键字</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">每页数据条数</param>
        /// <param name="ascending">排序</param>
        /// <response code="200"></response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WeChatKeywordDto>), 200)]
        public IActionResult Query([FromQuery(Name = "keyword")]string keyword = null,
            [FromQuery(Name = "start")]DateTime? start = null,
            [FromQuery(Name = "start")]DateTime? end = null,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10,
            [FromQuery(Name = "ascending")]bool? ascending = null)
        {
            return this.Ok(this.weChatKeywordService.GetWeChatKeywordList(keyword, start, end, index, size, ascending));
        }
        /// <summary>
        /// 修改微信关键字信息。
        /// </summary>
        /// <param name="weChatKeywordId">微信关键字Id</param>
        /// <param name="dto">微信关键字信息</param>
        /// <response code="200">修改是否成功</response>
        /// <returns></returns>
        [HttpPut("{we_chat_keyword_id}")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult Update([FromRoute(Name = "we_chat_keyword_id")]int weChatKeywordId, [FromBody]WeChatKeywordRequestDto dto)
        {
            return this.Ok(this.weChatKeywordService.Update(weChatKeywordId, dto));
        }
        /// <summary>
        /// 删除微信关键字信息。
        /// </summary>
        /// <param name="weChatKeywordId">微信关键字Id</param>
        /// <response code="204">删除成功</response>
        /// <returns></returns>
        [HttpDelete("{we_chat_keyword_id}")]
        public IActionResult Delete([FromRoute(Name = "we_chat_keyword_id")]int weChatKeywordId)
        {
            this.weChatKeywordService.Delete(weChatKeywordId);
            return this.NoContent();
        }
    }
}
